﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EQual.MainModule.Employees
{
    /// <summary>
    /// Interaction logic for DocumentsDestributionView.xaml
    /// </summary>
    public partial class EmployeesSelectionView : UserControl, EQual.MainModule.Employees.IEmployeesSelectionView 
    {
        public EmployeesSelectionView()
        {
            InitializeComponent();
        }

        public DataAccesLayer.Employee GetActiveItem()
        {
            return this.datagrid.SelectedItem as DataAccesLayer.Employee;
        }

        #region IDocumentsDestributionView Members

        [Obsolete ("Use Model",false )]
        public void SetModel(System .Collections .IEnumerable  model )
        {
            this.datagrid.ItemsSource = model;
        }
  
        #endregion

        private void datagrid_RowEditEnding(object sender, Microsoft.Windows.Controls.DataGridRowEditEndingEventArgs e)
        {
            if(ItemAdded != null )
            ItemAdded(this, new Microsoft.Practices.Composite.Events.DataEventArgs<object>(GetActiveItem()));
        }

        #region IListView<object,object> Members

        public object Model
        {
            get
            {
                return this.DataContext;
            }
            set
            {
                this.DataContext = value;
            }
        }

        public event EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> ItemSelected;

        public event EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> ItemDeleted;

        public event EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> ItemAdded;

        #endregion
    }

}
